package com.cavy.platform.server.dto;

import com.cavy.platform.server.domain.AbstractConfigMap;
import com.cavy.platform.server.domain.ConfigMapType;
import com.cavy.platform.server.validator.ConfigMapNotRepeat;
import com.cavy.platform.server.validator.FormatValidatorGroup;
import com.cavy.platform.server.validator.LastValidatorGroup;
import com.cavy.platform.server.validator.WorkspaceExist;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.GroupSequence;
import javax.validation.constraints.NotNull;

@Data
@GroupSequence({FormatValidatorGroup.class, LastValidatorGroup.class, AbstractConfigMapCreateDto.class})
@ConfigMapNotRepeat(message = "名称不能重复", groups = LastValidatorGroup.class)
public abstract class AbstractConfigMapCreateDto {
    @NotNull(message = "工作空间不能为空", groups = FormatValidatorGroup.class)
    @WorkspaceExist(groups = LastValidatorGroup.class)
    protected String workspace;
    @NotBlank(message = "名称不能为空", groups = FormatValidatorGroup.class)
    protected String name;

    protected ConfigMapType mapType = ConfigMapType.STRING;

    public String getNameField() {
        return "name";
    }

    public void setValue(AbstractConfigMap configMap) {
        configMap.setWorkSpace(workspace);
        configMap.setName(name);
    }
}
